package com.jiyi.activity.design;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.design.widget.TextInputLayout;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.EditText;

import com.swift.base.ActivityBase;
import com.swift.maintenance.R;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2018/1/19.
 */

public class DesignActivity extends ActivityBase {


    @BindView(R.id.fabSnackBar)
    FloatingActionButton fabSnackBar;
    @BindView(R.id.tilTextSize)
    TextInputLayout tilTextSize;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_design);
        ButterKnife.bind(this);

        initTextInputLayout();
    }

    private void initTextInputLayout() {
        tilTextSize.setHint("请输入不超过5个字符");
        EditText editText = tilTextSize.getEditText();
        editText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {

            }

            @Override
            public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
                if (charSequence.length()>5)
                {
                    tilTextSize.setError("不能输入超过5个字符");
                    tilTextSize.setErrorEnabled(true);
                }
                else
                {

                    tilTextSize.setErrorEnabled(false);
                }
            }

            @Override
            public void afterTextChanged(Editable editable) {

            }
        });
    }

    @OnClick(R.id.fabSnackBar)
    public void onClick() {
        final Snackbar snackbar = Snackbar.make(fabSnackBar, "测试", Snackbar.LENGTH_SHORT);
//        snackbar.setAction("知道了", new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                snackbar.dismiss();
//            }
//        });
        snackbar.show();
    }
}
